//
//  PassViewController.m
//  Drivinglicense
//
//  Created by HappyMilk 02 on 2017/6/30.
//  Copyright © 2017年 tomi. All rights reserved.
//

#import "PassViewController.h"
#import <SVProgressHUD.h>
#import "MJRequestServer.h"
#import "FormalTestController.h"
#import "QuestionModel.h"

@interface PassViewController ()

@property (weak, nonatomic) IBOutlet UIImageView *imgv_user;
@property (weak, nonatomic) IBOutlet UILabel *lab_user;
@property (weak, nonatomic) IBOutlet UILabel *lab_grades;
@property (weak, nonatomic) IBOutlet UIImageView *imgv_jige;
@property (weak, nonatomic) IBOutlet UIImageView *imgv_dongh;

@property (weak, nonatomic) IBOutlet UILabel *lab_dui;
@property (weak, nonatomic) IBOutlet UILabel *lab_cuo;
@property (weak, nonatomic) IBOutlet UILabel *lab_lou;


@end

@implementation PassViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.imgv_user.layer.masksToBounds = YES;
    self.imgv_user.layer.cornerRadius = 33;
    
    NSString *right = [_dataDic objectForKey:@"right"];
    NSString *fals = [_dataDic objectForKey:@"false"];
    int time = 2700-[[_dataDic objectForKey:@"time"] intValue];
    
    if ([right integerValue] < 90) {
        self.imgv_jige.image = [UIImage imageNamed:@"p_nopass"];
        self.imgv_dongh.image = [UIImage imageNamed:@"p_img2"];
    }
    int mm = time/60;
    int ss = time%60;
    NSString *shijian;
    if (ss>9) {
        shijian = [NSString stringWithFormat:@"%d:%d",mm,ss];
    }else{
        shijian = [NSString stringWithFormat:@"%d:0%d",mm,ss];
    }
    self.lab_grades.text = [NSString stringWithFormat:@"分数 %@   用时 %@",right,shijian];
    self.lab_dui.text = [NSString stringWithFormat:@"%@题",right];
    self.lab_cuo.text = [NSString stringWithFormat:@"%@题",fals];
    self.lab_lou.text = [NSString stringWithFormat:@"%d题",100-[right intValue]-[fals intValue]];
    
}
- (IBAction)retestAction:(UIButton *)sender {
    [SVProgressHUD show];
    NSDictionary *dic = @{@"type":@"C1",
                          @"subject":@"1",
                          @"pagesize":@"100",
                          @"pagenum":@"1",
                          @"sort":@"rand",
                          @"appkey":@"63a288a68764b5e2"};
    [MJRequestServer Post:dic success:^(id sender) {
        
        NSMutableArray *muarr = [QuestionModel mj_objectArrayWithKeyValuesArray:sender];
        
        [SVProgressHUD dismiss];
        
        UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
        FormalTestController *vc = [sb instantiateViewControllerWithIdentifier:@"FormalTestController"];
        vc.testArray = muarr;
        [self.navigationController pushViewController:vc animated:YES];
        
    } andFailure:^(id sender) {
        [SVProgressHUD showInfoWithStatus:@"请再次尝试"];
    }];
}
- (IBAction)popvc:(UIButton *)sender {
    [self.navigationController popToRootViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
